package org.hagopa.games.moneypool.game.gameobjects;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hagopa.games.moneypool.dblayer.Connector.DBConnector;


public class Board {
	private DBConnector localRefDBConn = null;
	private int gameId = 0;
	private int templateId = 0;
	private List <Field> LocList = null;
	private int maxLocations = 0;
	
	
	public Board(DBConnector ref2DBConn, int gameId, int templateId )
	{
		this.localRefDBConn = ref2DBConn;
		this.gameId = gameId;
		this.templateId = templateId;
		
		this.LocList = new ArrayList<Field>();
		
		System.out.println("Board object created.Game Id:" + this.gameId + "Tempplate Id: " + this.templateId);
	}
	
	public boolean updateBoard()
	{
		Field nextLocation = null;
		
		
		int tempType = 0;
		for(int i = 0; i < this.maxLocations; i++)
		{
			Property prop = new Property();
	//		PropertyData propData =  new PropertyData(i);
	//		propData.loadData();
//			if(propData.getType() == tempType)
//			{
//				prop.setCurrCost(65 + (i*10));
//				prop.setFee((65 + (i*10)) / 10);
//				prop.setName(propData.getName());
//				
//				nextLocation = new Field();
//				nextLocation.setIdOnBoard(i);
//				nextLocation.setPropOwner(0);
//				nextLocation.setProp(prop);
//			}
//			else
//			{
//				prop.setName("Service Squere");
//				nextLocation = new Field();
//				nextLocation.setIdOnBoard(i);
//				nextLocation.setPropOwner(0);
//				nextLocation.setProp(prop);
//			}
//			this.LocList.add(nextLocation);
//			
		}
		return true;
	}
	public List<Integer> getPlayersOnCurrentPos(int pos)
	{
		return this.LocList.get(pos).getPlayersList();
	}
	
	public Field getFieldById(int id)
	{
		Field tmp = null;
		synchronized (LocList) 
		{
			Iterator <Field> itr = LocList.iterator();
			while(itr.hasNext())
			{
				tmp = (Field)itr.next();
				if(tmp.getIdOnBoard() == id)
					return tmp;
			}
		}
		return null;
	}
	public void printStatus()
	{
		System.out.println("Current Board lenght: " + this.maxLocations);
		System.out.println("Current Locations in List: " + this.LocList.size() + "\n ---");
		Iterator<Field> itr = this.LocList.iterator();
		while(itr.hasNext())
		{
			Field tmp = itr.next();
			System.out.println("Place id on board: " + tmp.getIdOnBoard());
			System.out.println("Owner: " + tmp.getPropOwner());
			System.out.println("Property name: " + tmp.getProp().getName() );
			System.out.println("Property Cost: " + tmp.getProp().getCurrCost());
			System.out.println("Property upgrade level: " + tmp.getProp().getUpgradeLevel());
		}
	}
}
